﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace PrintBarcode
{
    public partial class Print_nhap_xuat_ton : UTLBASEFORM.MDICHILD
    {
        
        TProduct1 tProduct = new TProduct1();
        TProductType1 tProdType = new TProductType1();
        ReportDocument rptAllCustomersOrders = new ReportDocument();
        DataTable dataCat;
        Tcat1 tCat = new Tcat1();
        ds_nxt.sp_tmpDataTable tmptable;

        public Print_nhap_xuat_ton()
        {
            InitializeComponent();
        }

        private void Print_nhap_xuat_ton_Load(object sender, EventArgs e)
        {
            setupMenu();
            LoadCat();
            //LoadProductType();
        }
        public void LoadProductType()
        {
            DataTable data = tProdType.GetProType();
            cmbProductType.DisplayMember = data.Columns["Name"].ToString();
            cmbProductType.ValueMember = data.Columns["ID"].ToString();
            cmbProductType.DataSource = data;

        }
        public void LoadCat()
        {
            dataCat = tCat.GetCat();
            cmbProductType.DataSource = dataCat;
            cmbProductType.DisplayMember = dataCat.Columns["Name"].ToString();
            cmbProductType.ValueMember = dataCat.Columns["ID"].ToString();
        }
        private void setupMenu()
        {
            ShowBTN1("In", "");
            ShowBTN2("Lam Lai", "");
        }
        public override void btn1_Click(object sender, EventArgs e)
        {
            base.btn1_Click(sender, e);
        }
        public override void btn2_Click(object sender, EventArgs e)
        {
            base.btn2_Click(sender, e);
        }
        private void hienthi1()
        {
            tmptable.Clear();
            tmptable = new ds_nxtTableAdapters.sp_tmpTableAdapter().GetData(int.Parse(cmbProductType.SelectedValue.ToString()));

            reports.rpt_nxt document = new reports.rpt_nxt();

            document.SetDataSource((DataTable)tmptable);
            crystalReportViewer1.ReportSource = document;

            //ds_nxtTableAdapters.sp_tmpTableAdapter adapt = new ds_nxtTableAdapters.sp_tmpTableAdapter();
            //adapt.Connection.ConnectionString = "Data Source=CNTT\\LTTOI;Initial Catalog=hongphucgold;User ID=sa;Password=lttoi";
            //ds_nxt.sp_tmpDataTable table1 = new ds_nxt.sp_tmpDataTable();

            //adapt.Fill(table1, int.Parse(cmbProductType.SelectedValue.ToString()));




            //string localPath = Application.StartupPath;
            //string cc = @"..\..\reports\rpt_nxt.rpt";
            //rptAllCustomersOrders.Load(cc);
            //crystalReportViewer1.ReportSource = rptAllCustomersOrders;


            //crystalReportViewer1.Zoom(1);
            //rptAllCustomersOrders.Load("rpt_report_kd.rpt");
            //ReportDAO rpt = new ReportDAO();

            //rpt.kenoi(rptAllCustomersOrders);
            //rptAllCustomersOrders.DataSourceConnections[0].SetConnection("ECYBIZ3\\ECYBIZ3_LTTOI", "hongphucdb", "sa", "lttoi");

            //CrystalDecisions.Shared.ParameterDiscreteValue pdvCustomerName1 = new CrystalDecisions.Shared.ParameterDiscreteValue();
            ////CrystalDecisions.Shared.ParameterDiscreteValue pdvCustomerName2 = new CrystalDecisions.Shared.ParameterDiscreteValue();

            //CrystalDecisions.Shared.ParameterValues pvCollection1 = new CrystalDecisions.Shared.ParameterValues();
            ////CrystalDecisions.Shared.ParameterValues pvCollection2 = new CrystalDecisions.Shared.ParameterValues();

            //pdvCustomerName1.Value = cmbProductType.SelectedValue;
            ////pdvCustomerName2.Value = dateTimePicker1.Value.Year;

            //// Add it to the parameter collection.


            //pvCollection1.Add(pdvCustomerName1);
            //// pvCollection2.Add(pdvCustomerName2);

            //// Apply the current parameter values.


            //rptAllCustomersOrders.DataDefinition.ParameterFields["@idcat"].ApplyCurrentValues(pvCollection1);
            ////rptAllCustomersOrders.DataDefinition.ParameterFields["@year"].ApplyCurrentValues(pvCollection2);

            //// Hide group tree for this report


           
                        

        }
        
        private void hienthi()
        {

             string localPath = Application.StartupPath;
            string cc = @"..\..\reports\rpt_report_kd.rpt";
            rptAllCustomersOrders.Load(cc);
            //rptAllCustomersOrders.Load("rpt_report_kd.rpt");
            ReportDAO rpt = new ReportDAO();

            rpt.kenoi(rptAllCustomersOrders);
           //rptAllCustomersOrders.DataSourceConnections[0].SetConnection("ECYBIZ3\\ECYBIZ3_LTTOI", "hongphucdb", "sa", "lttoi");

            CrystalDecisions.Shared.ParameterDiscreteValue pdvCustomerName1 = new CrystalDecisions.Shared.ParameterDiscreteValue();
            CrystalDecisions.Shared.ParameterDiscreteValue pdvCustomerName2 = new CrystalDecisions.Shared.ParameterDiscreteValue();
            CrystalDecisions.Shared.ParameterDiscreteValue pdvCustomerName3 = new CrystalDecisions.Shared.ParameterDiscreteValue();

            CrystalDecisions.Shared.ParameterValues pvCollection1 = new CrystalDecisions.Shared.ParameterValues();
            CrystalDecisions.Shared.ParameterValues pvCollection2 = new CrystalDecisions.Shared.ParameterValues();
            CrystalDecisions.Shared.ParameterValues pvCollection3 = new CrystalDecisions.Shared.ParameterValues();

            pdvCustomerName1.Value = cmbProductType.SelectedValue;
                pdvCustomerName2.Value = dateTimePicker1.Value;
                pdvCustomerName3.Value = dateTimePicker2.Value;

            // Add it to the parameter collection.


            pvCollection1.Add(pdvCustomerName1);
            pvCollection2.Add(pdvCustomerName2);
            pvCollection3.Add(pdvCustomerName3);
            // Apply the current parameter values.


            rptAllCustomersOrders.DataDefinition.ParameterFields["@idcat"].ApplyCurrentValues(pvCollection1);
            rptAllCustomersOrders.DataDefinition.ParameterFields["@tungay"].ApplyCurrentValues(pvCollection2);
            rptAllCustomersOrders.DataDefinition.ParameterFields["@denngay"].ApplyCurrentValues(pvCollection3);

            // Hide group tree for this report


            crystalReportViewer1.ReportSource = rptAllCustomersOrders;


            crystalReportViewer1.Zoom(1);
                        

        }

       

        private void cmdxem_Click(object sender, EventArgs e)
        {
            hienthi();
        }

       
    }
}

